package com.smarthome.api.ipc;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.smarthome.domain.ipc.IpcRequest;

@Service("ipcServerCommandUtil")
public class IpcServerCommandUtil {

    private static long overTime = 30 * 1000;// 运行时间

    // @Resource
    // private IpcServerHandler ipcServerHandler;

    public JSONObject sendCommand(String ipcId, IpcRequest request) {
        // IoSession session = ipcServerHandler.getSessions().get(ApiCachedKeysUtil.getKey(ApiCachedKeysUtil.MODULE_IPC_SESSION, String.valueOf(ipcId).toUpperCase()));
        // JSONObject obj = new JSONObject();
        // if (session == null) {
        // obj.put("flag", false);
        // obj.put("msg", "要操作的设备未在线");
        // return obj;
        // }
        // // IoSession session = (IoSession)JedisUtils.get(ApiCachedKeysUtil.getKey(ApiCachedKeysUtil.MODULE_IPC_SESSION, String.valueOf(ipcId)));
        // String threadId = UUID.randomUUID().toString();
        // request.setThreadId(String.valueOf(threadId).toUpperCase());
        // String requestStr = CommandExporter.parseJsonForIpcRequest(request);
        // long beginTime = System.currentTimeMillis();// 开始时间
        // session.write(requestStr);
        // String key = ApiCachedKeysUtil.getKey(ApiCachedKeysUtil.MODULE_IPC_THREADID, String.valueOf(threadId).toUpperCase());
        // for (;;) {
        // if (JedisUtils.isExists(key)) {
        // return JedisUtils.get(key, JSONObject.class);
        // }
        // if (System.currentTimeMillis() - beginTime > overTime)
        // break;
        // }
        return null;
    }
}
